package com.yvan.simple;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.context.ApplicationListener;

public class AppStartListener implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {

    private static final Logger log = LoggerFactory.getLogger(ServerStart.class);

    @Override
    public void onApplicationEvent(EmbeddedServletContainerInitializedEvent event) {
        int port = event.getEmbeddedServletContainer().getPort();
        log.info("server started on port:" + port);
        if (ServerStart.OPEN_BROWSER) {
            OpenBrowser.open("http://localhost:" + port + "/index.html");
        }
    }
}
